package com.bage.finance.admin.api.controller;

import com.bage.common.dto.ApiResponse;
import com.bage.finance.biz.dto.form.GetSmsCodeForm;
import com.bage.finance.biz.service.MemberLoginService;
import com.bage.finance.biz.dto.form.GetBase64CodeForm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录controller
 *
 * @author Wei
 * @date 2024/07/13
 */
@Api(tags = "登录注册模块")
@RestController
@RequiredArgsConstructor
@RequestMapping("/login")
@Slf4j
public class LoginController {

    final MemberLoginService memberLoginService;

    @GetMapping("/getClientId")
    @ApiOperation("获取客户端ID")
    public ApiResponse<String> getClientId(){
        return ApiResponse.success(memberLoginService.getClientId());
    }

    @GetMapping("/getBase64Code")
    @ApiOperation("获取图像验证码")
    public ApiResponse<String> getBase64Code(@Validated @ModelAttribute GetBase64CodeForm form){
        return ApiResponse.success(memberLoginService.getBase64Code(form));
    }


    @ApiOperation(value = "获取短信验证码")
    @GetMapping(value = "/sendSmsCode")
    public ApiResponse<Void> sendSmsCode(@Validated @ModelAttribute GetSmsCodeForm request) {
        memberLoginService.sendSmsCode(request);
        // 只向前端发送是否成功状态信息即可
        return ApiResponse.success();
    }

}
